<?php
namespace app\model;

use think\Model;

class Member extends Model
{
    // 设置表名
    protected $table = 'member';
    
    // 自动时间戳
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    
    // 密码加密
    public function setPasswordAttr($value)
    {
        return password_hash($value, PASSWORD_DEFAULT);
    }
    
    // 验证密码
    public function verifyPassword($password)
    {
        return password_verify($password, $this->password);
    }
    
    // 关联观看历史
    public function histories()
    {
        return $this->hasMany('app\model\ViewHistory', 'member_id');
    }
}